package com.jiyun.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jiyun.pojo.ThStoreInformation;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jiyun.service.IThStoreInformationService;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  门店信息表
 * </p>
 *
 * @author usian
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/store_information")
@Api(tags = "接口")
@CrossOrigin
public class ThStoreInformationController{

    @Autowired
    private IThStoreInformationService thStoreInformationService;

    /**
     * 查询门店详情信息
     * @param storeId
     * @return
     */
    @GetMapping("/findById/{id}")
    public ThStoreInformation findById(@PathVariable("id") Integer storeId){
        if (storeId==null){
            throw new RuntimeException("参数有误");
        }
        LambdaQueryWrapper<ThStoreInformation> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(storeId!=null,ThStoreInformation::getStoreId,storeId);
        ThStoreInformation thStoreInformation = thStoreInformationService.getOne(queryWrapper);
        return thStoreInformation;
    }

    @PostMapping("/update")
    public String update(@RequestBody ThStoreInformation thStoreInformation,Integer userId){
        if ( userId!=1  ){
            throw new RuntimeException("您还不是专管员");
        }
        if (thStoreInformation==null || userId==null){
            throw new RuntimeException("参数有误");
        }
        boolean b = thStoreInformationService.updateById(thStoreInformation);
        if (!b){
            throw new RuntimeException("修改有误");
        }else {
            return "修改成功";
        }
    }
}
